<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <script src="../static/js/jquery.min.js"></script>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
    <script src="../static/js/bootstrap.min.js"></script>
    <title>提现申请</title>
    <link rel="stylesheet" href="style.css">
    <?php
    require_once "session.php";
    $weixin_id = $_SESSION["user"];
    $user = $core->GetUserByWxId($weixin_id);
    $bank_card = $core->GetCardsByUserId($user["id"]);
    $money = $_REQUEST["money"];
    $bonus = $user["remain_bonus"];
    $ky = (float)$bonus - (float)$money;
    ?>
</head>
<body>
<div id="head" style="position: relative;">
    <a href="javascript:history.go(-1)" class="back_btn">
        <span class="glyphicon glyphicon-chevron-left " style="line-height: 45px"></span>
    </a>
    <span style="font-size: 25px;">提现</span>
</div>
<div id="MainPanel">
    <div id="top">
        <div id="winthdraw_icon">
            <img src="../wap/system_icon/icon1.ico" alt="" style="width: 60px;height: 60px">
        </div>
        <div id="winthdraw_title">
            申请信息填写
        </div>
        <div id="winthdraw_msg" style="display: none"></div>
    </div>

    <div class="col-xs-12" style="margin-top: 15px;">
        <div class="panel">
            <div class="panel-body">
                <div class="form-group">
                    <div class="text-danger">
                        <span style="font-weight: bold;">注意：</span>
                        请仔细阅读后再填写
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group" style="width: 100%">
                        <span class="input-group-addon" style="width: 70px;text-align: right;">银行卡</span>
                        <select class="form-control" id="user_bankcard">
                            <?php
                            for ($a = 0; $a < count($bank_card); $a++) {
                                $num = substr($bank_card[$a]["card_num"], count($bank_card[$a]["card_num"]) - 5);
                                echo "<option value='" . $bank_card[$a]["id"] . "'>" . $bank_card[$a]["bank_name"] . " 尾号:" . $num . "</option>";
                            }
                            ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group" style="width: 100%">
                        <span class="input-group-addon" style="width: 70px;text-align: right;">可提现</span>
                        <input class="form-control text-right" id="user_bonus" disabled="disabled"
                               value="<?php echo "￥" . $ky . " 元" ?>"/>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group" style="width: 100%">
                        <span class="input-group-addon" style="width: 70px;text-align: right;">提现</span>
                        <input class="form-control" id="withdraw_money" onkeyup="clearNoNum(this)">
                    </div>
                </div>
                <div class="form-group">
                    <button class="btn btn-default btn-block " disabled="disabled" id="submit_btn">提交申请</button>
                </div>
            </div>
        </div>
    </div>

</div>
<script>

    function clearNoNum(obj) {
        obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
        obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
        input_money();
    }

    $('#withdraw_money').bind('input propertychange', input_money);

    function input_money() {
        var Withdraw_Money = $("#withdraw_money").val();
        var btn = document.getElementById("submit_btn");
        var bank = $('#user_bankcard').val();
        var a = /^[0-9]+\.$/;
        if (Withdraw_Money != "" && !a.test(Withdraw_Money) && Withdraw_Money != 0 && bank != null) {
            btn.style.backgroundColor = "rgb(255,137,0)";
            btn.style.color = "white";
            $("#submit_btn").removeAttr("disabled");
        } else {
            btn.style.backgroundColor = "rgb(221,221,221)";
            btn.style.color = "rgb(193,193,193)";
            btn.disabled = "disabled";
        }
    }

    var User_Bonus = <?php echo $ky; ?>;
    $("#submit_btn").on("touchend",function () {
        var money = $("#withdraw_money").val();
        var bonus = ($("#user_bonus").val()).substring(1,$("#user_bonus").val().length-2);
        if (parseFloat(money) <= parseFloat(bonus)) {
            var card_id = $("#user_bankcard").val();
            $.post("fun_user_withdraw.php", {money: money, card_id: card_id}, function (o) {
                if (o != "") {
                    alert(o);
                } else {
                    location.href = "Finish_Withdraw.php?card_id=" + card_id + "&money=" + money;
                }
            });
        } else {
            $("#winthdraw_msg").html("对不起，金额超限").show(500);
            setTimeout(function () {
                $("#winthdraw_msg").hide(500);
            }, 1500);
        }

    });
    $(function() {
        $("[ontouchend]").each(function(index, element) {
            var moved = false;
            var bindFn = function(touchEndFn) {
                if (!moved) {
                    eval(touchEndFn);
                }
                moved = false;
            }
            $(this).bind("touchend", bindFn.bind(this, $(this).attr("ontouchend")));
            $(this).bind("touchmove", function() {
                moved = true;
            });
            $(this).removeAttr("ontouchend");
        });

    })
</script>
</body>
</html>